<template>
    <div class="news-container">
        <h1>{{newsInfo.title}}</h1>
        <p class="news-time">
            <span>发表时间：{{newsInfo.add_time | dateFormat}}</span>
            <span>点击:{{newsInfo.click}}次</span>
        </p>
        <hr>
        <!-- 新闻的内容 -->
        <div class="new-content" v-html="newsInfo.content"></div>

        <!-- 新闻内容底部 的 评论区域 -->
        <comment :id="this.id"></comment>
    </div>
</template>

<script>
    // 引入 MUI
    import {Toast} from "mint-ui"
    //  引入子组件
    import comments from "./../comments/comments.vue"
    // 获取 路由传递的参数$route.params 来获取 :传递的数据 
    export default {
        data(){
            return {
                id:this.$route.params.id,
                newsInfo:{}  //因为在此页面不需要循环，所以直接拿到数据即可
            }
        },
        created(){
            this. getNewsInfo()
        },
        methods: {
            getNewsInfo(){
                this.$http.get("api/getnew/" + this.id).then(result => {
                    if(result.body.status==0){
                        this.newsInfo = result.body.message[0]
                    }else{
                        Toast("获取数据失败")
                    }
                })
            }
        },
        components:{
            comment:comments
        }
    }
</script>

<style lang="less" scoped>
    .news-container{
        padding: 0 5px;
        h1{
            font-size: 16px;
            color: red;
            text-align: center;
        }
        p{
            font-size: 14px;
            color: rgb(30, 188, 216);
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
        }
    }
</style>
